<?
	require_once "../db.php";
	extract($_POST);
	
	//echo "tmp_name = ".$_FILES['img_avatar']['tmp_name']."</br >";
	//echo "name = ".$_FILES['img_avatar']['name']."</br >";
	//echo "size = ".$_FILES['img_avatar']['size']." bytes</br >";
	//echo "type = ".$_FILES['img_avatar']['type']."</br >";
	//$t_nm = $_FILES['img_avatar']['tmp_name'];
	//$nm = $_FILES['img_avatar']['name'];
	//echo "</br >";
	//move_uploaded_file($t_nm,"imgs/".$nm);
	//echo "<img src='suse.png'></img>";

	if($txt_password == $txt_cpassword)
	{
		$pwd = $txt_password;
	}



	if(empty($_FILES["img_avatar"]["tmp_name"]))
	{
		$b = "haha";
	}
	else
	{
		if($image == "")
		{
			mkdir($username."/", 0777);
			mkdir($username."/avatar/");
			move_uploaded_file($_FILES["img_avatar"]["tmp_name"], $username."/avatar/".$_FILES["img_avatar"]["name"]);
			$image = $username."/avatar/".$_FILES["img_avatar"]["name"];
			$b .= $image."create";
		}
		else
		{
			unlink($image);
			move_uploaded_file($_FILES["img_avatar"]["tmp_name"], $username."/avatar/".$_FILES["img_avatar"]["name"]);
			$image = $username."/avatar/".$_FILES["img_avatar"]["name"];
			$b .= $image."update";
		}
	}

	session_start();

	$query = "update $type set password = '$pwd', name = '$txt_fullname', dob = '$txt_dob', address = '$txt_address', city = '$txt_city', state = '$txt_state', contact = '$txt_contact',image = '$image', web_page = '$txt_web_page', experience = '$txt_experience' where username = '$username'";

	$result = mysql_query($query);

	//$a = mysql_error();

	if($result)
	{
		header("location:profile_update.php?username=$username&msg=update successfully!!!");
	}
	else
	{
		header("location:profile_update.php?username=$username&msg=not update...");
	}

?>
